package com.bjx.flow.mmx.extension;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.bjx.flow.mmx.bean.MmxNodeData;
import com.bjx.flow.mmx.bean.MmxNodeProperties;

import java.util.List;
import java.util.Map;

/**
 * @desc: 审批人抽象接口
 * @author: liushuai
 * @date: 2023/2/8 10:27
 */
public abstract class MmxAbstractApprover {

    public List<String> getApprover(MmxNodeData nodeData, Map<String, Object> variables) {
        MmxNodeProperties properties = nodeData.getProperties();
        //优先使用自定义接口
        List<String> assigneeList = this.customApprover(nodeData, variables);
        if (CollectionUtil.isEmpty(assigneeList)) {
            //使用固定用户
            if (StrUtil.isNotEmpty(properties.getAssignee())) {
                String[] assignees = properties.getAssignee().split(",");
                return ListUtil.toList(assignees);
            } else {
                throw new IllegalArgumentException("审批用户不存在");
            }
        }
        return assigneeList;
    }

    /**
     * 自定义审批人
     *
     * @param nodeData
     * @param variables
     * @return: java.util.List<java.lang.String>
     * @Author: liushuai
     * @Date: 2023/2/8 10:44
     */
    public abstract List<String> customApprover(MmxNodeData nodeData, Map<String, Object> variables);
}
